refactor(doclinks): unify link handlers and validate all file links#1348
refactor(doclinks): unify link handlers and validate all file links#1348
Conversation
Add Pattern 3 to doclinks that validates existing .md links in docs: - Resolves relative .md paths to absolute links - Validates absolute .md links exist on disk - Falls back to doc_index search for broken links with disambiguation - Handles index.md files by searching parent dir name - Scores candidates by directory overlap + filename match Delete duplicate docs/usage/transports.md (identical to transports/index.md). Fixes 5 broken links across docs/ (agents/docs/index.md, capabilities/ navigation/readme.md, usage/lcm.md).
Greptile SummaryThis PR consolidates 3 separate regex patterns and handlers in Key improvements:
The refactor is backward-compatible and all existing behaviors are preserved. The 9 new tests provide comprehensive coverage of the disambiguation logic, link validation, and edge cases. Confidence Score: 5/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[process_markdown] --> B{Split by ignore regions}
B --> C[Process each region]
C --> D{Apply code_pattern}
D --> E[replace_code_match]
E --> F{File has extension or /?}
F -->|No| G[Skip]
F -->|Yes| H[file_index lookup]
H --> I[resolve_candidates]
I --> J{Candidates count}
J -->|0| K[Error: not found]
J -->|1| L[Use single match]
J -->|Multiple| M[pick_best_candidate]
M --> N{score_path_similarity}
N -->|Unique max| O[Use best match]
N -->|Tie| P[Error: ambiguous]
C --> Q{Apply link_pattern}
Q --> R[replace_link_match]
R --> S{Link type?}
S -->|.md placeholder| T[doc_index lookup]
S -->|Absolute path| U{File exists?}
S -->|Relative path| V{File exists?}
S -->|URL/anchor| W[Skip]
T --> I
U -->|No| X[_search_fallback]
V -->|No| X
X --> Y{Has extension?}
Y -->|.md| Z[doc_index search]
Y -->|Other| AA[file_index search]
Z --> I
AA --> I
Last reviewed commit: 4a6848b |
|
Looks good, but it would be nice to have a test which fails if there are invalid links in .md files. |
yeah pre-commit hooks will fail you on this since they run doclinks on all files |
Problem
Doclinks validates all links and tries to intelligently re-link if stuff is moved, insists on absolute links everywhere, shares more code between .md link resolution and .py etc resolution.
updates existing docs/ links
Doclinks is vibed
we don't care about the code here, just speed & correct behaviour, review by looking at docs/ changes
How to Test
Contributor License Agreement